//
//  HWVoiceRoomGiftCenterBgProtocol.swift
//  PlayWithProject
//
//  Created by 王昌健 on 2021/8/27.
//

import UIKit

class HWVoiceRoomGiftCenterBgProtocol: NSObject,UICollectionViewDelegate,UICollectionViewDataSource,UICollectionViewDelegateFlowLayout {
    var models:[HWVoiceRoomGiftModel]?
    var didSelectRow:((_:HWVoiceRoomGiftModel)->())?
    func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) {
        for mod in models ?? []{
            mod.selected = false
        }
        models?[indexPath.row].selected = !(models?[indexPath.row].selected ?? false)
        collectionView.reloadData()
        didSelectRow?(models![indexPath.row])
    }
    func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, minimumInteritemSpacingForSectionAt section: Int) -> CGFloat {
        return 0
    }
    func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
        return models?.count ?? 0
    }
    
    func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
        let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "HWVoiceRoomGiftCell", for: indexPath) as! HWVoiceRoomGiftCell
        cell.model = models?[indexPath.row]
        return cell
    }
    

}
